from tb_info.function.user_list import *


def add_org_people2():
    # downtree()
    data = get_org_people(4)
    for i in data:
        TbOrg.objects.filter(id=i['org_id']).update(org_people=i["num"])
    orgID = [org.id for org in TbOrg.objects.all()]
    for id2 in orgID:
        list1 = [id2]
        list2 = []
        list3 = []
        list4 = []
        r1,r2 = downtree(list1,list2,list3)
        org_list3 = list(set(r1).union(set(r2)))
        # d = get_full_org3(48)
        # print(org_list3)
        for i in org_list3:
            num = TbUserOrg.objects.filter(org_id=i).count()
            list4.append(num)
        all_num = sum(list4)
        TbOrg.objects.filter(id=id2).update(org_people_all=all_num)